using Godot;

public partial class CPreSkillState : CState
{
    public override void run(Node n, double delta)
    {
        if (n is NCharacter cha)
        {
            CSkill skill = cha.getSkill(cha.mData.mSkillTarget.mID);
            SKILL_RE sr = skill.canPlay(cha);
            if (sr == SKILL_RE.NO_TARGET)
            {
                cha.mData.mState = new CIdleState();
                return;
            }
            if (sr == SKILL_RE.NO_ENOUGH_DIS)
            {
                if (skill.mPutTarget == SKILL_TARGET.ENEMY_TARGET)
                {
                    NCharacter targetCha = cha.GetNodeOrNull<NCharacter>(cha.mData.mSkillTarget.mTargetPath);
                    if (targetCha != null && CHelp.canBattle(targetCha, cha))
                    {
                        CHelp.doMove(cha, targetCha.GlobalPosition, delta);
                        cha.play(ANI_TYPE.WALK);
                    }
                }
            }
            if (sr == SKILL_RE.SUCCESS)
            {
                cha.mData.mState = new CDoSkillState();
                return;
            }
            if (sr == SKILL_RE.UNKNOW)
            {
                cha.mData.mState = new CIdleState();
                return;
            }
        }
    }
}